<?php $this->Hinc('header')?>
<link href="/Public/Home/public/all_common.css" rel="stylesheet" type="text/css">
<div class="container clearfix">
     <div class="shop-cart-box-hd">
         <h2 class="title">我的购物车</h2>
         <p class="tip">全场包邮</p>
     </div>
     <div class="navbar">
            <span class="on">1.我的购物车</span>
            <span>2.填写核对订单信息</span>
            <span>3.成功提交订单</span>
     </div>
     <div class="shop-cart-box-bd">
         
         <table class="shop-cart-goods" cellpadding="0" cellspacing="0">
             <thead>
             <tr>
                 <th class=" col-1">商品名称</th>
                 <th class=" col-2">价格</th>
                 <th class=" col-2">购买数量</th>
                 <th class=" col-2">小计</th>
                 <th class=" col-2">操作</th>
             </tr>
             </thead>
            <tbody>
			<?php foreach($arr as $v){?>
				<tr>
                    <td class="col col-1">
						<!--多选框-->
						<div>
							<input type="checkbox" class="che" data="<?php echo $v['id']?>">
						</div>
                            <div class="g-pic">
                                <a href="<?php $this->U('Index','goods&id='.$v['g_id'])?>" target="_blank">
									<img src="<?php echo substr(strrchr($v['img'],'|'),1)?>" border="0" title="<?php echo $v['name']?>">
								</a>
                            </div>
                            <div class="g-info">
                             <div class="g-name">
                              <a href="<?php $this->U('Index','goods&id='.$v['g_id'])?>" target="_blank">
								  <?php echo $v['name']?>
								  &nbsp;
								  &nbsp;
								  &nbsp;
								  |
								  规格   &nbsp; <?php echo $v['gname']?>
							  </a>
							 </div>
							 </div>
                    </td>
                    <td class="col col-2">
                     ￥ <b class="jg_<?php echo $v['id']?>"><?php echo $v['money']+$v['gmoney']?></b>
					</td>
                    <td class="col col-2">
						<div class="change-goods-num">
                            <a href="javascript:void(0);" data="jian" iop="<?php echo $v['id']?>"  class="xgnum">
                                -
                            </a>

							<input disabled tyep="text" name="number" value="<?php echo $v['num']?>" autocomplete="off" class="goods-num num_<?php echo $v['id']?>">
							<!--库存-->
							<input type="hidden" class="kc_<?php echo $v['id']?>" value="<?php echo $v['kc']?>">


                            <a href="javascript:void(0);" data="jia" iop="<?php echo $v['id']?>" class="xgnum">
                                +
                            </a>
                        </div>
					</td>
                    <td class="col col-2">
                        <em id="goods_subtotal_996543">
							<!--小计-->
							￥ <b class="xj_<?php echo $v['id']?>"><?php echo ($v['money']+$v['gmoney'])*$v['num']?></b>
						</em>
					</td>
                    <td class="col col-2">
						<a data="<?php echo $v['id']?>" class="goods-del" href="javascript:void(0)">X</a>
					</td>
                </tr>
			<?php }?>
			</tbody>
         </table>



         <div class="total">
             总金额：<span id="money">￥<b id="zje">0</b></span>元
                       </div>
         <div class="go-next clearfix">
             <a class="btn btn-back " href="<?php $this->U('Index','lis')?>"> 继续购物 </a>&nbsp;&nbsp;
             <a class="btn btn-primary" id="qjz">去结账</a>
         </div>
     </div>
  </div>
<script>
    //修改总金额方法
    function zje(){
        //获取所有的选中的多选框
        var money=0;
        $('.che').each(function (i,t) {
            if($(t).is(':checked')){
                //得到对应的小计
                var id=$(t).attr('data');

                money+=Number($('.xj_'+id).html());
            }
        });
        //修改总金额
        $('#zje').html(money.toFixed(2));
    }
    $(function () {
        //去结账
		$('#qjz').click(function () {
			//获取选中的数据id
			var id='';
			$('.che').each(function (i,t) {
				if($(t).is(":checked")){
				    id+=$(t).attr('data')+',';
				}
            });
			if(!id){
			    alert('请选择结算商品!谢谢');
			    return false;
			}
			//购物流程2
			location.href="/index.php?C=Order&F=index2&id="+id;
        });

        //删除操作
        $('.goods-del').click(function () {
            if(!confirm('是否删除')){
                return false;
            }

            var id=$(this).attr('data');
            $.get('<?php $this->U(Order,flow_del)?>',{id:id},function (msg) {
                alert(msg.msg)
                if(msg.type==1){
                    history.go(0);
                }
            },'json')
        });


        //改变总金额
        $('.che').click(function () {
            zje()
        });

        //改变小计
        $('.xgnum').click(function () {
            var type=$(this).attr('data'); //类型
            var id=$(this).attr('iop'); //数据id
            var num=Number($('.num_'+id).val()); //数量
            var kc=Number($('.kc_'+id).val());
            if(type=='jia'){
                var nums=num+1<kc?num+1:kc;

            }else{
                var nums=num-1>1?num-1:1;
            }
            //发送ajax
            $.get("<?php $this->U('Order','flow_edit')?>",{id:id,num:nums},function(abc){
                //小计=商品原来的价格 * 新的数量
                //var jg=Number($('.jg_'+id).html());
                if(abc.type==1){
                    $('.xj_'+id).html(abc.msg);//修改小计
                    $('.num_'+id).val(nums); //修改数量

                    zje();
                }else{
                    alert(abc.msg);
                }
            },'json');
        })
    })
</script>
<?php $this->Hinc('footer')?>